package com.yygo.service.impl;

import com.yygo.dao.VehicleSeriesDao;
import com.yygo.model.VehicleModel;
import com.yygo.model.VehicleSeries;
import com.yygo.service.VehicleSeriesManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
 * Created by tiansha on 2015/6/23.
 */
@Service("vehicleSeriesManager")
public class VehicleSeriesManagerImpl extends GenericManagerImpl<VehicleSeries, Long> implements VehicleSeriesManager {

    private VehicleSeriesDao vehicleSeriesDao;

    @Autowired
    public VehicleSeriesManagerImpl(VehicleSeriesDao vehicleSeriesDao) {
        super(vehicleSeriesDao);
        this.vehicleSeriesDao = vehicleSeriesDao;
    }

    @Override
    public List<VehicleModel> getMyModels(String seriesName, boolean isSecond){
        Set<VehicleModel> vehicleModels = vehicleSeriesDao.getMyModels(seriesName, isSecond);
        List<VehicleModel> vehicleModelList = new ArrayList<VehicleModel>();
        vehicleModelList.addAll(vehicleModels);
        vehicleModelList.sort(new Comparator<VehicleModel>() {
            @Override
            public int compare(VehicleModel o1, VehicleModel o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        return vehicleModelList;
    }
}
